<?php
require_once 'AccessControl.php';

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->access = new AccessControl(); //实例化访问控制类
    }

    //首页显示公告
    public function indexAction()
    {
        $pagesize = 3; //页面容量
        $pid = $this->getRequest()->getUserParam('pid');
        $this->view->showpage = true;
        
        $noticeDb = new Application_Model_DbTable_Notice();
        $notices_count = $noticeDb->countNotices();
        
        if($notices_count <= $pagesize)
            $this->view->showpage = false;
        
        if($this->view->showpage && isset($pid) && $pid > 1)
        {
            if($notices_count % $pagesize)
            {
                $pages = (INT)($notices_count/$pagesize+1);//有余数的情况
            }
            else
                $pages = $notices_count/$pagesize;
            
            //如果 pid 不合法直接跳转首页
            if($pid <= $pages)
            {
                $notices = $noticeDb->getNoticesByRange($pagesize*($pid-1),$pagesize);
                $this->view->pages = $pages;
            }
            else
                $this->_redirect('');
            
        }
        else
        {
            $notices = $noticeDb->getNoticesByRange(0,$pagesize);
            $pid = 1;
        }
        
        $this->view->pid = $pid;
        $this->view->notices = $notices;
        $this->view->admin = $this->access->isAdmin();
    }

}





